package edu.sctu.zhuyingzhi.month201505.day20150504.exception.judgeArrayV1;

import javax.swing.*;

/**
 * Created by user13 on 2015/5/4.
 */
public class JudgeArray{

    public void array() throws NegativeArraySizeException,ArrayIndexOutOfBoundsException {
        int inputvalue, i;
        String input;
        int array[];
        do {
            input = JOptionPane.showInputDialog("请输入长度");
            inputvalue = Integer.parseInt(input);

                array = new int[inputvalue];

                for (i = 0; i < 5; i++) {
                    System.out.println("输出：" + array[i] + "   i=" + i);

                }

        } while (inputvalue < 5);

    }

    public void catchException(){
        try {
            array();
        }
        catch (NegativeArraySizeException e) {

            System.out.println("catch exception.");
            JOptionPane.showMessageDialog(null, "数组长度为负数 不符合要求");

        }
        catch (ArrayIndexOutOfBoundsException f) {
            JOptionPane.showMessageDialog(null, "数组长度越界 不符合要求");
        }
    }



}

